package me.jiatao.jetpack

import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*


fun main() = runBlocking {
//    val stateFlow = MutableStateFlow(0)
//
//    // 监听stateFlow的变化
//    val job = launch {
//        stateFlow.collect {
//            println("$it ")
//        }
//    }
//
//    // 修改stateFlow的值
//    (1..5).forEach {
//        delay(500)
//        stateFlow.value = it
//    }
//
//    // Cancel running job
//    job.cancel()
//    job.join()


    val stateFlow = (1..10).asFlow().map {
        delay(200)
        it
    }.stateIn(GlobalScope)

    delay(1000)

    stateFlow.collect(::print)
}